/*
 * @Description: API分组信息 - 接口
 * @Author: DHL
 * @Date: 2022-03-20 20:29:53
 * @LastEditors: DHL
 * @LastEditTime: 2022-03-24 15:01:47
 */

import { $get, $post, $put } from '/@/utils/http'
import { ContentTypeEnum } from '/@/constant/http'
import {
  ApiGroupModel,
  ApiGroupPageParams,
  ApiGroupPageResultModel,
  ApiGroupResultModel,
  ApiGroupListResultModel,
  ApiGroupParams
} from './model/apiGroupModel'

/**
 * 分页查询
 */
export const apiApiGroupSearch = (searchParams: ApiGroupPageParams) =>
  $get<ApiGroupPageResultModel>({
    url: '/auth/twbApiGroup/search',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const apiApiGroupGetById = (id: string) =>
  $get<ApiGroupResultModel>({
    url: '/auth/twbApiGroup/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const apiApiGroupSave = (saveParams: ApiGroupModel) =>
  $post<ApiGroupResultModel>({
    url: '/auth/twbApiGroup/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const apiApiGroupUpdateById = (updateParams: ApiGroupModel) =>
  $put<ApiGroupResultModel>({
    url: '/auth/twbApiGroup/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })

/**
 * 根据ID删除信息
 */
export const apiApiGroupDeleteById = (id: string) =>
  $post<ApiGroupResultModel>({
    url: '/auth/twbApiGroup/deleteById',
    params: { id: id }
  })

/**
 * 批量删除信息
 */
export const apiApiGroupBatchDeleteByIds = (ids: string) =>
  $post<ApiGroupResultModel>({
    url: '/auth/twbApiGroup/batchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 根据ID逻辑删除信息
 */
export const apiApiGroupLogicDeleteById = (id: string) =>
  $post<ApiGroupResultModel>({
    url: '/auth/twbApiGroup/logicDeleteById',
    params: { id: id }
  })

/**
 * 批量逻辑删除
 */
export const apiApiGroupLogicBatchDeleteByIds = (ids: string) =>
  $post<ApiGroupResultModel>({
    url: '/auth/twbApiGroup/logicBatchDeleteByIds',
    params: { ids: ids }
  })

/**
 * api组树结构查询
 * @param searchParams
 * @returns
 */
export const apiApiGroupSearchTree = (searchParams: ApiGroupParams) =>
  $get<ApiGroupListResultModel>({
    url: '/auth/twbApiGroup/searchTree',
    params: searchParams
  })

/**
 * 批量更新Api信息
 * @param params
 * @returns
 */
export const apiApiGroupRefreshApis = (params: {
  projectId: string
  apiGroupPid: string
  type: string
  packagesOrClasses: string
}) =>
  $post<ApiGroupListResultModel>({
    url: '/auth/twbApiGroup/refreshApis',
    params: params
  })
